/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights
 * reserved. <a>http://www.cqcis.com</a>
 */
package com.cqcis.uip.base.framework.core.impl;

import java.util.List;

import org.apache.log4j.Appender;

import com.cqcis.uip.base.framework.core.LogRepositoryService;
import com.cqcis.uip.base.framework.core.LogService;
import com.cqcis.uip.base.logadaptor.LogConfiguration;

/**
 * @author huangmy
 * @date 2008-2-2
 */
public class LogServiceImpl implements LogService {
	private LogRepositoryService logRespositoryService;

	public List<Appender> getAppenders(Thread thread) {
		return logRespositoryService.getAppenders(thread);
	}

	public void register(LogConfiguration logConfiguration) {
		try {
			register(logConfiguration, Thread.currentThread());
		} catch (Throwable t) {
		}
	}

	public void unregister() {
		try {
			unregister(Thread.currentThread());
		} catch (Throwable t) {
		}
	}

	public List<LogConfiguration> getLogConfiguration(Thread thread) {
		return logRespositoryService.getLogConfigurations(thread);
	}

	public void register(LogConfiguration logConfiguration, Thread thread) {
		try {
			logRespositoryService.register(logConfiguration, thread);
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}

	public void unregister(Thread thread) {
		try {
			logRespositoryService.unregister(thread);
		} catch (Throwable t) {
		}
	}

	public void removeLogConfiguration(LogConfiguration logConfiguration,
			Thread thread) {
		try {
			logRespositoryService.removeLogConfiguration(logConfiguration, thread);
		} catch (Throwable t) {
		}
	}

	public void tryCloseLogAppender(LogConfiguration logConfiguration) {
		try {
			logRespositoryService.tryCloseLogAppender(logConfiguration);
		} catch (Throwable t) {
		}
	}

	public void setLogRespositoryService(LogRepositoryService logRespositoryService) {
		this.logRespositoryService = logRespositoryService;
	}
}
